package com.example.myapplication.NettyClient;

import android.util.Log;

import com.example.myapplication.Base.BaseActivity;

import java.util.concurrent.TimeUnit;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.EventLoop;

/**
 * Author by lp,on 2021/11/15/015,13:38.
 */
public class ConnectListener implements ChannelFutureListener {

    private static final String TAG = "ConnectListener";
    @Override
    public void operationComplete(ChannelFuture channelFuture) throws Exception {
        Log.i(TAG, "operationComplete: "+channelFuture.toString());
        //连接失败发起重连
        if (!channelFuture.isSuccess()) {
            final EventLoop loop = channelFuture.channel().eventLoop();
            loop.schedule(new Runnable() {
                @Override
                public void run() {
                    Log.e(TAG, "连接失败，发起重连");
                    BaseActivity.client.reConnect();
                }
            }, 5, TimeUnit.SECONDS);
        }
    }

}
